import express, { Express, Request, Response } from 'express';
import dotenv from 'dotenv';
import cors from 'cors';
import guessRoute from './routes/guess'; // 引入路由

dotenv.config(); // Load environment variables from .env file

const app: Express = express();
const port = process.env.PORT || 3000;

// --- Middleware Configuration ---
// Enable CORS (configure as needed for production)
app.use(cors());

// Parse JSON request bodies
// Increase limit to handle base64 image data
app.use(express.json({ limit: '10mb' }));

// Parse URL-encoded request bodies (optional, but often useful)
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
// ---------------------------

// Base route for checking if the server is running
app.get('/', (req: Request, res: Response) => {
  res.send('AI Draw & Guess - Backend Server Running!');
});

// --- API Routes Will Go Here ---
app.use('/api/guess', guessRoute); // 使用路由
// ------------------------------

app.listen(port, () => {
  console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
});

export default app; // Export app for testing or other purposes 